package src.leetcode.backtrack.medium_0078;

import java.util.ArrayList;
import java.util.List;

public class subsets {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.subsets(new int[]{1, 2, 3}));
    }
}

class Solution {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    int[] nums;
    int index = 0;
    public List<List<Integer>> subsets(int[] nums) {
        res.add(path);
        this.nums = nums;
        dfs();
        return res;
    }

    private void dfs() {

        if (index == nums.length) {
            return;
        }

        for (int i = index; i < nums.length; i++) {
            path.add(nums[i]);
            res.add(new ArrayList<>(path));
            index = i + 1;
            dfs();
            path.remove(path.size() - 1);
        }

    }
}